package com.ruoyi.wx.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wx.mapper.GoodskindsMapper;
import com.ruoyi.wx.domain.Goodskinds;
import com.ruoyi.wx.service.IGoodskindsService;

/**
 * 商品分类Service业务层处理
 *
 * @author hxie
 * @date 2020-12-25
 */
@Service
public class GoodskindsServiceImpl implements IGoodskindsService
{
    @Autowired
    private GoodskindsMapper goodskindsMapper;

    /**
     * 查询商品分类
     *
     * @param kindsId 商品分类ID
     * @return 商品分类
     */
    @Override
    public Goodskinds selectGoodskindsById(Long kindsId)
    {
        return goodskindsMapper.selectGoodskindsById(kindsId);
    }


    /**
     * 查询商品分类
     *
     * @param kindsName 商品分类ID
     * @return 商品分类
     */
    @Override
    public Goodskinds selectGoodskindsByName(String kindsName)
    {
        return goodskindsMapper.selectGoodskindsByName(kindsName);
    }

    /**
     * 查询商品分类列表
     *
     * @param goodskinds 商品分类
     * @return 商品分类
     */
    @Override
    public List<Goodskinds> selectGoodskindsList(Goodskinds goodskinds)
    {
        return goodskindsMapper.selectGoodskindsList(goodskinds);
    }

    /**
     * 新增商品分类
     *
     * @param goodskinds 商品分类
     * @return 结果
     */
    @Override
    public int insertGoodskinds(Goodskinds goodskinds)
    {
        goodskinds.setCreateTime(DateUtils.getNowDate());
        return goodskindsMapper.insertGoodskinds(goodskinds);
    }

    /**
     * 修改商品分类
     *
     * @param goodskinds 商品分类
     * @return 结果
     */
    @Override
    public int updateGoodskinds(Goodskinds goodskinds)
    {
        goodskinds.setUpdateTime(DateUtils.getNowDate());
        return goodskindsMapper.updateGoodskinds(goodskinds);
    }

    /**
     * 批量删除商品分类
     *
     * @param kindsIds 需要删除的商品分类ID
     * @return 结果
     */
    @Override
    public int deleteGoodskindsByIds(Long[] kindsIds)
    {
        return goodskindsMapper.deleteGoodskindsByIds(kindsIds);
    }


    /**
     * 校验岗位名称是否唯一
     *
     * @param goodskinds 岗位信息
     * @return 结果
     */
    @Override
    public String checkKindsNameUnique(Goodskinds goodskinds)
    {
        Long kindsId = StringUtils.isNull(goodskinds.getKindsId()) ? -1L : goodskinds.getKindsId();
        Goodskinds info = goodskindsMapper.checkKindsNameUnique(goodskinds.getKindsName());
        if (StringUtils.isNotNull(info) && info.getKindsId().longValue() != kindsId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 删除商品分类信息
     *
     * @param kindsId 商品分类ID
     * @return 结果
     */
    @Override
    public int deleteGoodskindsById(Long kindsId)
    {
        return goodskindsMapper.deleteGoodskindsById(kindsId);
    }

}
